#deploy document management site


#re-create the site collection
$webAppUrl = "http://turnersintranet"
$siteCollectionUrl = "http://turnersintranet/sites/DMS"
$siteName = "DMS"
$siteTemplateId = "STS#0" #team site
$primaryAdminAccount = "Auctions\intergen-admin"

#add solution
$wspPackagePath = "C:\Users\intergen-admin\Desktop\DMS\DMS\bin\Debug\DMS.wsp"
$wspPackageName = "DMS.wsp" 


#@@@@@@@@@@@@@@@@@@@@@@@variables can't be change from this point@@@@@@@@@@@@@@@@@@@@
#activate feature
$recreateSiteCollection = $true

$searchSiteRelativeUrl = "Search"
$invoiceSiteRelativeUrl = "Invoices"
$caSiteRelativeUrl = "CreditApplications"
$gatSiteRelativeUrl = "GATs"


$dmsBrandingFeatureId="28509740-6361-4d6f-b34d-dad9f4804277"
$listProvisioningFeatureId="dd04962e-73b4-4021-83bf-95129703e6f0"
$documentStoreFeatureId="62bf7719-32c1-41f8-8ad8-b94c4887c63b"
$searchProvisionFeatureId="341b093a-f997-4454-b887-3105a9919945"


$invoiceHomepageFeatureId = "eedea87f-e153-41e7-b386-3bd766d8703a"
$caHomepageFeatureId = "e44372bb-c758-497f-ae04-9342e1ee035c"
$gatHomepageFeatureId = "dc553a03-b207-4303-8758-e95d2e25ab1c"


#@@@@@@@@@@@@ No Change Required From THIS LINE @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue


Update-SPSolution -Identity $wspPackageName -LiteralPath $wspPackagePath -GACDeployment

stsadm -o execadmsvcjobs

Start-Sleep 30

<#
Write-Host "retracting solution"
stsadm -o retractsolution -name $wspPackageName -immediate -url $webAppUrl
Start-Sleep 20
stsadm -o execadmsvcjobs

Start-Sleep 10
Write-Host "deleting solution"
stsadm -o deletesolution -name $wspPackageName
Start-Sleep 10
#>

#uninstall and remove solution before delete site collection


Write-Host "Deactivating feature DocumentStore..."
stsadm -o deactivatefeature -id $documentStoreFeatureId -url $siteCollectionUrl -force 
Start-Sleep 20
Write-Host "Activating feature DocumentStore..."
stsadm -o activatefeature -id $documentStoreFeatureId -url $siteCollectionUrl -force 
Start-Sleep 20


Write-Host "Deployment Completed Successfully." -ForegroundColor Green

#add solution
#Write-Host "Adding Solution ..."
#Add-SPSolution $wspPackagePath
#Write-Host "Awaiting Adding Solution Finish..."
#Start-Sleep -Seconds 30

#Write-Host "Deploying Solution ..."
#Install-SPSolution -identity $wspPackageName -webApplication $WebAppUrl -GACDeployment
#Write-Host "Awaiting Install Solution Finish..."
#Start-Sleep -Seconds 30


#activate feature
#Write-Host "Activating Site Feature Branding..."
#Enable-SPFeature -identity $dmsBrandingFeatureId -url $siteCollectionUrl -Force
#Start-Sleep -Seconds 30

#Write-Host "Activating Site Feature List Provisioning..."
#Enable-SPFeature -identity $listProvisioningFeatureId -url $siteCollectionUrl -Force
#Start-Sleep -Seconds 30

#Write-Host "Activating Document Store Event Receiver ..."
#Enable-SPFeature -identity $documentStoreFeatureId -url $siteCollectionUrl -Force
#Start-Sleep -Seconds 30

#activate web features

#search site
#Write-Host "Activating Feature Search Provisioning on $seachSiteUrl..."
#Enable-SPFeature -identity $searchProvisionFeatureId -url $seachSiteUrl -Force
#Start-Sleep -Seconds 30
#invoices site
#Write-Host "Activating Feature Invoice Subsite Provisioning on $invoiceSiteUrl..."
#Enable-SPFeature -identity $invoiceHomepageFeatureId -url $invoiceSiteUrl -Force
#Start-Sleep -Seconds 30
#gat site
#Write-Host "Activating Feature GATs Subsite Provisioning on $gatSiteUrl..."
#Enable-SPFeature -identity $gatHomepageFeatureId -url $gatSiteUrl -Force
#Start-Sleep -Seconds 30
#ca site
#Write-Host "Activating Feature Credit Applications Subsite Provisioning on $caSiteUrl..."

#Enable-SPFeature -identity $caHomepageFeatureId -url $caSiteUrl -Force
#Start-Sleep -Seconds 30



Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue